package com.share.admin.config.security.bean;

import com.share.common.utils.Md5Util;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

@Component
public class MyPasswordEncoder implements PasswordEncoder {

    @Override
    public String encode(CharSequence password) {
        return Md5Util.encodeByMD5(password.toString());
    }

    /**
     * @param password        前端传递的明文密码
     * @param encodedPassword 数据库中的加密密码
     * @return
     */
    @Override
    public boolean matches(CharSequence password, String encodedPassword) {
        String pw = this.encode(password);
        return encodedPassword.equals(pw);
    }
}
